package com.xiecong.config;

import com.xiecong.interceptor.DemoInterceptor;
import com.xiecong.interceptor.TokenInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//@Configuration//配置类，不是读取配置文件内容。而是来创建bean对象到spring容器中的
public class WebConfig implements WebMvcConfigurer {

    //@Autowired
    private DemoInterceptor demoInterceptor;
    //@Autowired
    private TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(demoInterceptor) //registry注册器，把拦截器添加到拦截器列表里
                .addPathPatterns("/**") //配置拦截的路径
                .excludePathPatterns("/login"); //不拦截的路径

        // 创建TokenInterceptor拦截器对象
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login");
    }
}
